﻿/**
 * @file MainForm
 *
 * @brief 
 *
 * @author gyzheng
 *
 * @mail gyazheng@gmail.com
 *
 * @date 07/27/2011 22:37:51 
 *
 */
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace CarFrameWork.UI.Common
{
    public partial class ListForm : ChildrenForm
    {
        protected object m_CurrentNode;
        public ListForm()
        {
            InitializeComponent();
            Init();
        }

        protected virtual void BindGridData()
        { }

        private void Init()
        {   
            dgMain.CurrentCellChanged+=new EventHandler(dgMain_CurrentCellChanged);
            dgMain.MouseDown+=new MouseEventHandler(dgMain_MouseDown);
            dgMain.DoubleClick+=new EventHandler(dgMain_DoubleClick);            
        }

        private void dgMain_CurrentCellChanged(object sender, EventArgs e)
        {
            this.SetLogic();
        }

        private void dgMain_MouseDown(object sender, MouseEventArgs e)
        {
            if (dgMain.CurrentRowIndex == 0)
                SetLogic();
        }

        protected virtual void SetLogic()
        { 
        }

        protected virtual void dgMain_DoubleClick(object sender, EventArgs e)
        {

        }

        protected void SetRecordsCount(int recordCount)
        {
            lblRecord.Text = string.Format("当前一共检索出 {0} 条记录", recordCount);
        }

        #region EventHandler
        protected virtual void tbcAdd_Commanded(object sender, EventArgs e)
        {

        }

        protected virtual void tbcModify_Commanded(object sender, EventArgs e)
        {

        }

        protected virtual void tbcView_Commanded(object sender, EventArgs e)
        {

        }

        protected virtual void tbcDelete_Commanded(object sender, EventArgs e)
        {

        }
        #endregion

        #region CommonMethod
        protected void GetSelectNode()
        {
            if (this.dgMain.DataSource == null)
            {
                m_CurrentNode = null;
                return;
            }

            if (this.dgMain.CurrentRowIndex == -1)
            {
                m_CurrentNode = null;
                return;
            }

            m_CurrentNode = this.dgMain.BindingContext[this.dgMain.DataSource].Current;
        }
        #endregion
    }
}
